package com.cwrl.spider.protocol.lwm2m.listener;

import com.cwrl.spider.protocol.lwm2m.cache.Lwm2mServerCache;
import lombok.RequiredArgsConstructor;
import org.eclipse.leshan.core.observation.Observation;
import org.eclipse.leshan.server.registration.Registration;
import org.eclipse.leshan.server.registration.RegistrationListener;
import org.eclipse.leshan.server.registration.RegistrationUpdate;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Component
@RequiredArgsConstructor
public class MyRegistrationListener implements RegistrationListener {
    @Override
    public void registered(Registration registration, Registration previousReg, Collection<Observation> previousObservations) {
        Lwm2mServerCache.Client.addCache(registration.getEndpoint(), registration);
        // 设备注册上来了 接下来要给添加对应的监听

    }

    @Override
    public void updated(RegistrationUpdate update, Registration updatedReg, Registration previousReg) {
        Lwm2mServerCache.Client.addCache(updatedReg.getEndpoint(), updatedReg);
    }

    @Override
    public void unregistered(Registration registration, Collection<Observation> observations, boolean expired, Registration newReg) {
        Lwm2mServerCache.Client.removeCache(registration.getEndpoint());
    }
}
